home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1610 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.5 KB

  1. Path: news.nacm.com!usenet
  2. From: brandon@criterion.com (Brandon Wallace)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: mmap question
  5. Date: 15 Jan 1996 20:43:51 GMT
  6. Organization: Nicholas|Applegate Capital Management, San Diego, CA
  7. Message-ID: <4deea7$7cp@news.nacm.com>
  8. References: <4cgm6a$1n2@holodeck.iss.nus.sg>
  9. NNTP-Posting-Host: 204.255.80.4
  10. X-Newsreader: knews 0.9.2
  11.  
  12. In article <4cgm6a$1n2@holodeck.iss.nus.sg>,
  13.     paulwu@iss.nus.sg (Paul Wu) writes:
  14. -> Hi, there,
  15. -> 
  16. ->   It's myself again. I think I have solved my previous problem by changing 
  17. -> the file POINTER to be file DESCRIPTOR (using open rather than fopen) and 
  18. -> a bit careful about the constraints posed on the off argument. 
  19. -> 
  20. ->   Now the problem is I encounter a bus error SIGBUS (10) when I am actually 
  21. -> accessing the mapped memory, as an array. Anything about the other
  22. -> parameters that I should pay attention to, again my codes look like:
  23. -> 
  24. ->   ctr_tbl->trieArray=(UC_TRIE_NODE *)(mmap((caddr_t)0, off_set2, 
  25. ->           PROT_READ, MAP_SHARED, *fdesc, (off_t)(off_set1-j))+j);
  26. -> 
  27. -> Should I be more careful about the PROT_READ and MAP_SHARED parameters?
  28. -> 
  29. ->   One last question, for those who have used mmap, does it really help?
  30. -> If so, in what particular aspects it helps? Is it the run time? or is it
  31. -> the saving of space? BUt it seems not likely for the latter, since it 
  32. -> eats up the virtual memory anyway..
  33. -> 
  34. -> Appreciated,
  35. -> Paul
  36.  
  37. Why don't you just do:
  38.  
  39. ctr_tbl->trieArray = (UC_TRIE_NODE *) mmap (0, off_set2/* I hope this is a length parameter
  40.                                                           that is an integral multiple of sizeof (UC_TRIE_NODE) */
  41.                                             , PROT_READ, MAP_SHARED, *fdesc, off_set1);
  42.  
  43. instead of subtracting and adding j.  Also, since you pass PROT_READ, you cannot modify
  44. this data, so you should probably cast it to a (UC_TRIE_NODE const *) instead.  Make sure
  45. off_set1 satisfies the alignment constraints that the man pages mention.  If it does not,
  46. then the way to fix it is to modify the file to meet these constraints, not to subtract
  47. j and then add it again after the call.  Also note: don't store pointers in this mapped file
  48. because everytime you run the program, mmap() might return a different address and the 
  49. pointers will be invalid.
  50. -- 
  51.                       Brandon Wallace
  52.             Nicholas | Applegate Capital Management
  53. mailto:bman@criterion.com  http://www.criterion.com/home-pages/brandon
  54.           "I live life face down in the fast lane."
  55.  
  56.